@echo off
chcp 65001 >nul

REM 基本设置
set JAVA_HOME=C:\Program Files\Java\jdk-21
set SRC_DIR=src\main\java
set TARGET_DIR=target\classes

REM 创建目标目录
if not exist "%TARGET_DIR%" mkdir "%TARGET_DIR%"

REM 复制资源文件
xcopy /s /y "src\main\resources\*" "%TARGET_DIR%" >nul

REM 查找所有Spring和相关依赖的jar文件
set DEPENDENCIES=
for /r "%USERPROFILE%\.m2\repository" %%i in (*.jar) do (
    set "DEPENDENCIES=!DEPENDENCIES!;%%i"
)

REM 设置类路径
set CLASSPATH=%TARGET_DIR%;%DEPENDENCIES%

REM 编译Java源码
"%JAVA_HOME%\bin\javac.exe" -encoding UTF-8 -cp "%CLASSPATH%" -d "%TARGET_DIR%" "%SRC_DIR%\com\example\deepseek\backend\DeepSeekBackendApplication.java"

REM 检查编译是否成功
if %ERRORLEVEL% neq 0 (
    echo 编译失败！请检查错误信息。
    pause
    exit /b 1
)

REM 运行应用程序
"%JAVA_HOME%\bin\java.exe" -cp "%CLASSPATH%" com.example.deepseek.backend.DeepSeekBackendApplication

pause